# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

load("//rules:otbn.bzl", "otbn_binary", "otbn_library")

package(default_visibility = ["//visibility:public"])

otbn_binary(
    name = "boot",
    srcs = [
        "boot.s",
    ],
    deps = [
        ":p256_base",
        ":p256_isoncurve",
        ":p256_sign",
        ":p256_verify",
    ],
)

otbn_library(
    name = "ed25519",
    srcs = [
        "ed25519.s",
    ],
)

otbn_library(
    name = "ed25519_scalar",
    srcs = [
        "ed25519_scalar.s",
    ],
)

otbn_library(
    name = "div",
    srcs = [
        "div.s",
    ],
)

otbn_library(
    name = "field25519",
    srcs = [
        "field25519.s",
    ],
)

otbn_library(
    name = "gcd",
    srcs = [
        "gcd.s",
    ],
)

otbn_library(
    name = "lcm",
    srcs = [
        "lcm.s",
    ],
)

otbn_library(
    name = "modexp",
    srcs = [
        "modexp.s",
    ],
)

otbn_library(
    name = "montmul",
    srcs = [
        "montmul.s",
    ],
)

otbn_library(
    name = "mul",
    srcs = [
        "mul.s",
    ],
)

otbn_library(
    name = "p256_shared_key",
    srcs = [
        "p256_shared_key.s",
    ],
)

otbn_library(
    name = "p256_base",
    srcs = [
        "p256_base.s",
    ],
)

otbn_library(
    name = "p256_isoncurve",
    srcs = [
        "p256_isoncurve.s",
    ],
)

otbn_library(
    name = "p256_isoncurve_proj",
    srcs = [
        "p256_isoncurve_proj.s",
    ],
)

otbn_library(
    name = "p256_sign",
    srcs = [
        "p256_sign.s",
    ],
)

otbn_library(
    name = "p256_verify",
    srcs = [
        "p256_verify.s",
    ],
)

otbn_binary(
    name = "run_p256",
    srcs = [
        "run_p256.s",
    ],
    deps = [
        ":p256_base",
        ":p256_isoncurve",
        ":p256_isoncurve_proj",
        ":p256_shared_key",
        ":p256_sign",
        ":p256_verify",
    ],
)

otbn_library(
    name = "p384_base",
    srcs = [
        "p384_base.s",
    ],
)

otbn_library(
    name = "p384_a2b",
    srcs = [
        "p384_a2b.s",
    ],
)

otbn_library(
    name = "p384_b2a",
    srcs = [
        "p384_b2a.s",
    ],
)

otbn_library(
    name = "p384_isoncurve",
    srcs = [
        "p384_isoncurve.s",
    ],
)

otbn_library(
    name = "p384_isoncurve_proj",
    srcs = [
        "p384_isoncurve_proj.s",
    ],
)

otbn_library(
    name = "p384_sign",
    srcs = [
        "p384_sign.s",
    ],
)

otbn_library(
    name = "p384_internal_mult",
    srcs = [
        "p384_internal_mult.s",
    ],
)

otbn_library(
    name = "p384_keygen",
    srcs = [
        "p384_keygen.s",
    ],
)

otbn_library(
    name = "p384_keygen_from_seed",
    srcs = [
        "p384_keygen_from_seed.s",
    ],
)

otbn_library(
    name = "p384_base_mult",
    srcs = [
        "p384_base_mult.s",
    ],
)

otbn_library(
    name = "p384_modinv",
    srcs = [
        "p384_modinv.s",
    ],
)

otbn_library(
    name = "p384_scalar_mult",
    srcs = [
        "p384_scalar_mult.s",
    ],
)

otbn_library(
    name = "p384_verify",
    srcs = [
        "p384_verify.s",
    ],
)

otbn_library(
    name = "primality",
    srcs = [
        "primality.s",
    ],
)

otbn_binary(
    name = "rsa",
    srcs = [
        "rsa.s",
    ],
    deps = [
        ":modexp",
        ":montmul",
    ],
)

otbn_library(
    name = "run_rsa_modexp_mem",
    srcs = [
        "run_rsa_modexp_mem.s",
    ],
)

otbn_binary(
    name = "run_rsa_modexp",
    srcs = [
        "run_rsa_modexp.s",
    ],
    deps = [
        ":modexp",
        ":montmul",
        ":run_rsa_modexp_mem",
    ],
)

otbn_library(
    name = "run_rsa_keygen_mem",
    srcs = [
        "run_rsa_keygen_mem.s",
    ],
)

otbn_library(
    name = "rsa_keygen",
    srcs = [
        "rsa_keygen.s",
    ],
)

otbn_binary(
    name = "run_rsa_keygen",
    srcs = [
        "run_rsa_keygen.s",
    ],
    deps = [
        ":div",
        ":gcd",
        ":lcm",
        ":montmul",
        ":mul",
        ":primality",
        ":rsa_keygen",
        ":run_rsa_keygen_mem",
    ],
)

otbn_library(
    name = "rsa_verify",
    srcs = [
        "rsa_verify.s",
    ],
)

otbn_library(
    name = "rsa_verify_3072",
    srcs = [
        "//sw/vendor:veri-titan/gen/otbn_modexp.s",
    ],
)

otbn_library(
    name = "rsa_verify_3072_m0inv",
    srcs = [
        "rsa_verify_3072_m0inv.s",
    ],
)

otbn_library(
    name = "rsa_verify_3072_rr",
    srcs = [
        "rsa_verify_3072_rr.s",
    ],
)

otbn_binary(
    name = "run_rsa_verify_3072",
    srcs = [
        "run_rsa_verify_3072.s",
    ],
    deps = [
        ":rsa_verify_3072",
        ":rsa_verify_3072_m0inv",
        ":rsa_verify_3072_rr",
    ],
)

otbn_binary(
    name = "run_rsa_verify_3072_rr_modexp",
    srcs = [
        "run_rsa_verify_3072_rr_modexp.s",
    ],
    deps = [
        ":rsa_verify_3072",
        ":rsa_verify_3072_rr",
    ],
)

otbn_binary(
    name = "p256_ecdsa_sca",
    srcs = [
        "p256_ecdsa_sca.s",
    ],
    deps = [
        ":p256_base",
        ":p256_isoncurve",
        ":p256_sign",
        ":p256_verify",
    ],
)

otbn_binary(
    name = "p256_key_from_seed_sca",
    srcs = [
        "p256_key_from_seed_sca.s",
    ],
    deps = [
        ":p256_base",
        ":p256_isoncurve",
    ],
)

otbn_binary(
    name = "p256_mod_inv_sca",
    srcs = [
        "p256_mod_inv_sca.s",
    ],
    deps = [
        ":p256_base",
        ":p256_isoncurve",
    ],
)

otbn_binary(
    name = "p384_ecdsa_sca",
    srcs = [
        "p384_ecdsa_sca.s",
    ],
    deps = [
        ":p384_base",
        ":p384_internal_mult",
        ":p384_isoncurve",
        ":p384_modinv",
        ":p384_sign",
    ],
)

otbn_binary(
    name = "run_p384",
    srcs = [
        "run_p384.s",
    ],
    deps = [
        ":p384_a2b",
        ":p384_b2a",
        ":p384_base",
        ":p384_base_mult",
        ":p384_internal_mult",
        ":p384_isoncurve",
        ":p384_isoncurve_proj",
        ":p384_keygen",
        ":p384_keygen_from_seed",
        ":p384_modinv",
        ":p384_scalar_mult",
        ":p384_sign",
        ":p384_verify",
    ],
)

otbn_library(
    name = "sha256",
    srcs = [
        "sha256.s",
    ],
)

otbn_binary(
    name = "run_sha256",
    srcs = [
        "run_sha256.s",
    ],
    deps = [
        ":sha256",
    ],
)

otbn_library(
    name = "sha512",
    srcs = [
        "sha512.s",
    ],
)

otbn_binary(
    name = "run_sha512",
    srcs = [
        "run_sha512.s",
    ],
    deps = [
        ":sha512",
    ],
)

otbn_library(
    name = "sha512_compact",
    srcs = [
        "sha512_compact.s",
    ],
)

otbn_library(
    name = "sha3_shake",
    srcs = [
        "sha3_shake.s",
    ],
)

otbn_library(
    name = "x25519",
    srcs = [
        "x25519.s",
    ],
)

otbn_binary(
    name = "x25519_sideload",
    srcs = [
        "x25519_sideload.s",
    ],
    deps = [
        ":field25519",
        ":x25519",
    ],
)
